<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card class="box-card">
      <!-- 搜索与添加区域 -->

      <el-row :gutter="20">
        <el-col :span="10">
          <div>
            <el-input
              placeholder="请输入内容"
              v-model="queryInfo.query"
              clearable
              @clear="getOrderList"
            >
              <el-button
                slot="append"
                icon="el-icon-search"
                @click="getOrderList"
              ></el-button>
            </el-input>
          </div>
        </el-col>
      </el-row>
    </el-card>
    <!-- 数据展示 -->
    <el-table :data="orderList" style="width: 100%" border stripe>
      <el-table-column type="index" label="#"></el-table-column>
      <el-table-column prop="order_number" label="订单编号"> </el-table-column>
      <el-table-column prop="order_price" label="订单价格(元)" width="150px">
      </el-table-column>
      <el-table-column prop="pay_status" label="是否付款" width="150px">
        <template slot-scope="scope">
          <el-tag type="warning" v-if="scope.row.pay_status === '1'"
            >已付款</el-tag
          >
          <el-tag type="success" v-else>已付款</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="is_send" label="是否发货" width="80px">
      </el-table-column>
      <el-table-column prop="create_time" label="下单时间" width="150px">
        <template slot-scope="scope">
          {{ scope.row.create_time | dateFormat }}
        </template>
      </el-table-column>
      <el-table-column label="操作" width="150px">
        <template slot-scope="scope">
          <!-- 修改按钮
          <el-button
            type="primary"
            icon="el-icon-edit"
            size="mini"
            @click="showEditDialog(scope.row)"
          ></el-button> -->
          <!-- 查看物流的按钮 -->
          <el-button
            type="success"
            icon="el-icon-location-outline"
            size="mini"
            @click="showProgressBox"
          >查看物流</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页区域 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="queryInfo.pagenum"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="queryInfo.pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>

    <!-- 修改地址的弹框 -->
    <el-dialog
      title="修改地址"
      :visible.sync="addressVisible"
      width="50%"
      @close="editAddressClosed"
    >
      <!-- 内容主体区 -->
      <el-form
        :model="editAddressForm"
        :rules="editAddressFormRules"
        ref="editAddressFormRef"
        label-width="100px"
      >
        <el-form-item label="省市/区" prop="address1">
          <el-cascader
            v-model="editAddressForm.address1"
            :options="cityData"
            clearable
          ></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="editAddressForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <!-- 底部区域 -->
      <span slot="footer" class="dialog-footer">
        <el-button @click="removeAddress">取 消</el-button>
        <el-button type="primary" @click="editAddress">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 查看物流信息 -->
    <el-dialog title="物流进度" :visible.sync="progressVisible" width="50%">
      <!-- 内容主体区 -->
      <el-timeline>
        <el-timeline-item
          v-for="(activity, index) in progressInfo"
          :key="index"
          :timestamp="activity.time"
        >
          {{ activity.context }}
        </el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>
</template>

<script>
import {progress} from './progress.js'
import cityData from './citydata.js'
import { reqBannerList } from '../../mock/mockServer'
export default {
  name: 'Order',
  data() {
    return {
      queryInfo: {
        //搜索关键字
        query: '',
        //当前页数
        pagenum: 1,
        //当前每页显示多少条数据
        pagesize: 5,
      },
      orderList: [],
      total: 0,
      addressVisible: false,
      editAddressForm: { address1: [], address2: [] },
      editAddressFormRules: {
        address1: [{ required: true, message: '请输入地址', trigger: 'blur' }],
        address2: [
          { required: true, message: '请输入详细地址', trigger: 'blur' },
        ],
      },
      cityData,
      addressInfo: {},
      progressVisible: false,
      progressInfo:progress.data,
    }
  },
  created() {
    // this.reqBannerList()
    this.getOrderList()
  },
  methods: {
    //获取列表数据
    async getOrderList() {
      const { data: res } = await this.$http.get('orders', {
        params: this.queryInfo,
      })
      if (res.meta.status !== 200) {
        return this.$message.error('获取商品列表失败')
      }
      console.log(res.data)
      this.orderList = res.data.goods
      this.total = res.data.total
    },
    //修改一页显示的条数
    handleSizeChange(newSize) {
      this.queryInfo.pagesize = newSize
      this.getOrderList()
    },
    //修改页数，跳转到那一页
    handleCurrentChange(newPage) {
      this.queryInfo.pagenum = newPage
      this.getOrderList()
    },
    showEditDialog(addressInfo) {
      this.addressInfo = addressInfo
      this.addressVisible = true
    },
    editAddressClosed() {
      this.$refs.editAddressFormRef.resetFields()
    },
    removeAddress() {
      this.addressVisible = false
      this.$message.info('已取消修改')
    },
    editAddress() {},
    async showProgressBox() {
      // const { data: res } = await this.$http.get('/kuaidi/804909574412544580')
      // if (res.meta.status !== 200) {
      //   return this.$message.error('获取物流信息失败')
      // }
      // this.progressInfo = res.data
      // console.log(this.progressInfo)
      this.progressVisible = true
    },
    // async reqBannerList() {
    //   const { data: res } = await reqBannerList()
    // },
  },
}
</script>

<style>
</style>